#include <iostream>
#include <stdio.h>

/*
 * 调用静态虚函数	P139
 */

class Base
{
	public:
		virtual void demo(void) {
			printf("Base demon\n");
		}

		virtual void demo_2(void) {
			printf("Base demon_2\n");
		}

		void demo_3(void) {
			printf("Nonvirtual Base demon_3\n");
		}
};

class Derived : public Base
{
	public:
		virtual void demo(void) {
			printf("Derived demon\n");
		}

		virtual void demo_2(void) {
			printf("Derived demon_2\n");
		}

		void demo_3(void) {
			printf("Nonvirtual Derived demon_3\n");
		}
};

int main()
{
	Base p;
	
	p.demo();
	p.demo_2();
	p.demo_3();

	Derived d;
	d.demo();
	d.demo_2();
	d.demo_3();
}

/*
	Base demon
	Base demon_2
	Nonvirtual Base demon_3
	Derived demon
	Derived demon_2
	Nonvirtual Derived demon_3
 */

 #if 0

/*
 * intel
 */
00000000000011a9 <main>:
    11a9:	f3 0f 1e fa          	endbr64 
    11ad:	55                   	push   %rbp
    11ae:	48 89 e5             	mov    %rsp,%rbp
    11b1:	48 83 ec 20          	sub    $0x20,%rsp
    11b5:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11bc:	00 00 
    11be:	48 89 45 f8          	mov    %rax,-0x8(%rbp)		// rbp-0x8=rax
    11c2:	31 c0                	xor    %eax,%eax		// eax=0
    11c4:	48 8d 05 95 2b 00 00 	lea    0x2b95(%rip),%rax        # 3d60 <_ZTV4Base+0x10>	// rax=rip+0x2b95
    11cb:	48 89 45 e8          	mov    %rax,-0x18(%rbp)		// rbp-0x18=rax
    11cf:	48 8d 45 e8          	lea    -0x18(%rbp),%rax		// rax=rbp-0x18
    11d3:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11d6:	e8 c9 00 00 00       	callq  12a4 <_ZN4Base4demoEv>	// demo(rdi)
    11db:	48 8d 45 e8          	lea    -0x18(%rbp),%rax		// rax=rbp-0x18
    11df:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11e2:	e8 dd 00 00 00       	callq  12c4 <_ZN4Base6demo_2Ev>	// demo_2(x0)
    11e7:	48 8d 45 e8          	lea    -0x18(%rbp),%rax		// rax=rbp-0x18
    11eb:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    11ee:	e8 f1 00 00 00       	callq  12e4 <_ZN4Base6demo_3Ev>	// demo_3(rdi)
    11f3:	48 8d 05 46 2b 00 00 	lea    0x2b46(%rip),%rax        # 3d40 <_ZTV7Derived+0x10>	// rax=rip+0x2b46
    11fa:	48 89 45 f0          	mov    %rax,-0x10(%rbp)		// rbp-0x18=rax
    11fe:	48 8d 45 f0          	lea    -0x10(%rbp),%rax		// rax=rbp-0x10
    1202:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    1205:	e8 fa 00 00 00       	callq  1304 <_ZN7Derived4demoEv>	// demo(rdi)
    120a:	48 8d 45 f0          	lea    -0x10(%rbp),%rax		// rax=rbp-0x10
    120e:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    1211:	e8 0e 01 00 00       	callq  1324 <_ZN7Derived6demo_2Ev>	// demo_2(rdi)
    1216:	48 8d 45 f0          	lea    -0x10(%rbp),%rax		// rax=rbp-0x10
    121a:	48 89 c7             	mov    %rax,%rdi		// rdi=rax
    121d:	e8 22 01 00 00       	callq  1344 <_ZN7Derived6demo_3Ev>	// demo_3(rdi)
    1222:	b8 00 00 00 00       	mov    $0x0,%eax		// eax=0
    1227:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx		// rdx=rbp-0x8
    122b:	64 48 33 14 25 28 00 	xor    %fs:0x28,%rdx
    1232:	00 00 
    1234:	74 05                	je     123b <main+0x92>
    1236:	e8 55 fe ff ff       	callq  1090 <__stack_chk_fail@plt>
    123b:	c9                   	leaveq 
    123c:	c3                   	retq   

00000000000012a4 <_ZN4Base4demoEv>:
    12a4:	f3 0f 1e fa          	endbr64 
    12a8:	55                   	push   %rbp
    12a9:	48 89 e5             	mov    %rsp,%rbp
    12ac:	48 83 ec 10          	sub    $0x10,%rsp
    12b0:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12b4:	48 8d 3d 4a 0d 00 00 	lea    0xd4a(%rip),%rdi        # 2005 <_ZStL19piecewise_construct+0x1>
    12bb:	e8 f0 fd ff ff       	callq  10b0 <puts@plt>
    12c0:	90                   	nop
    12c1:	c9                   	leaveq 
    12c2:	c3                   	retq   
    12c3:	90                   	nop

00000000000012c4 <_ZN4Base6demo_2Ev>:
    12c4:	f3 0f 1e fa          	endbr64 
    12c8:	55                   	push   %rbp
    12c9:	48 89 e5             	mov    %rsp,%rbp
    12cc:	48 83 ec 10          	sub    $0x10,%rsp
    12d0:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12d4:	48 8d 3d 35 0d 00 00 	lea    0xd35(%rip),%rdi        # 2010 <_ZStL19piecewise_construct+0xc>
    12db:	e8 d0 fd ff ff       	callq  10b0 <puts@plt>
    12e0:	90                   	nop
    12e1:	c9                   	leaveq 
    12e2:	c3                   	retq   
    12e3:	90                   	nop

00000000000012e4 <_ZN4Base6demo_3Ev>:
    12e4:	f3 0f 1e fa          	endbr64 
    12e8:	55                   	push   %rbp
    12e9:	48 89 e5             	mov    %rsp,%rbp
    12ec:	48 83 ec 10          	sub    $0x10,%rsp
    12f0:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    12f4:	48 8d 3d 22 0d 00 00 	lea    0xd22(%rip),%rdi        # 201d <_ZStL19piecewise_construct+0x19>
    12fb:	e8 b0 fd ff ff       	callq  10b0 <puts@plt>
    1300:	90                   	nop
    1301:	c9                   	leaveq 
    1302:	c3                   	retq   
    1303:	90                   	nop

0000000000001304 <_ZN7Derived4demoEv>:
    1304:	f3 0f 1e fa          	endbr64 
    1308:	55                   	push   %rbp
    1309:	48 89 e5             	mov    %rsp,%rbp
    130c:	48 83 ec 10          	sub    $0x10,%rsp
    1310:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    1314:	48 8d 3d 1a 0d 00 00 	lea    0xd1a(%rip),%rdi        # 2035 <_ZStL19piecewise_construct+0x31>
    131b:	e8 90 fd ff ff       	callq  10b0 <puts@plt>
    1320:	90                   	nop
    1321:	c9                   	leaveq 
    1322:	c3                   	retq   
    1323:	90                   	nop

0000000000001324 <_ZN7Derived6demo_2Ev>:
    1324:	f3 0f 1e fa          	endbr64 
    1328:	55                   	push   %rbp
    1329:	48 89 e5             	mov    %rsp,%rbp
    132c:	48 83 ec 10          	sub    $0x10,%rsp
    1330:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    1334:	48 8d 3d 08 0d 00 00 	lea    0xd08(%rip),%rdi        # 2043 <_ZStL19piecewise_construct+0x3f>
    133b:	e8 70 fd ff ff       	callq  10b0 <puts@plt>
    1340:	90                   	nop
    1341:	c9                   	leaveq 
    1342:	c3                   	retq   
    1343:	90                   	nop

0000000000001344 <_ZN7Derived6demo_3Ev>:
    1344:	f3 0f 1e fa          	endbr64 
    1348:	55                   	push   %rbp
    1349:	48 89 e5             	mov    %rsp,%rbp
    134c:	48 83 ec 10          	sub    $0x10,%rsp
    1350:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    1354:	48 8d 3d f8 0c 00 00 	lea    0xcf8(%rip),%rdi        # 2053 <_ZStL19piecewise_construct+0x4f>
    135b:	e8 50 fd ff ff       	callq  10b0 <puts@plt>
    1360:	90                   	nop
    1361:	c9                   	leaveq 
    1362:	c3                   	retq   
    1363:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    136a:	00 00 00 
    136d:	0f 1f 00             	nopl   (%rax)

/*
 * arm
 */
000000000040084c <main>:
  40084c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400850:	910003fd 	mov	x29, sp				// x29=fp=sp
  400854:	90000000 	adrp	x0, 400000 <_init-0x6a0>	
  400858:	912d8000 	add	x0, x0, #0xb60
  40085c:	f9000fa0 	str	x0, [x29, #24]			// x29+24=400b60
  400860:	910063a0 	add	x0, x29, #0x18			// x0=x29+x018
  400864:	94000030 	bl	400924 <_ZN4Base4demoEv>	// base->demo(x0)
  400868:	910063a0 	add	x0, x29, #0x18			// x0=x28+0x18
  40086c:	94000037 	bl	400948 <_ZN4Base6demo_2Ev>	// base->demo_2(x0)
  400870:	910063a0 	add	x0, x29, #0x18			// x0=x29+0x18
  400874:	9400003e 	bl	40096c <_ZN4Base6demo_3Ev>	// base->demo_3(x0)
  400878:	90000000 	adrp	x0, 400000 <_init-0x6a0>	
  40087c:	912d0000 	add	x0, x0, #0xb40
  400880:	f9000ba0 	str	x0, [x29, #16]			// x29+16=x0=400b40
  400884:	910043a0 	add	x0, x29, #0x10			// x0=x29+0x10
  400888:	94000042 	bl	400990 <_ZN7Derived4demoEv>	// derived->demo(x0)
  40088c:	910043a0 	add	x0, x29, #0x10			// x0=x29+0x10
  400890:	94000049 	bl	4009b4 <_ZN7Derived6demo_2Ev>	// derived->demo_2(x0)
  400894:	910043a0 	add	x0, x29, #0x10			// x0=x29+0x10
  400898:	94000050 	bl	4009d8 <_ZN7Derived6demo_3Ev>	// derived->demo_3(x0)
  40089c:	52800000 	mov	w0, #0x0                   	// #0
  4008a0:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4008a4:	d65f03c0 	ret

0000000000400924 <_ZN4Base4demoEv>:
  400924:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400928:	910003fd 	mov	x29, sp
  40092c:	f9000fa0 	str	x0, [x29, #24]
  400930:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  400934:	912ae000 	add	x0, x0, #0xab8
  400938:	97ffff82 	bl	400740 <puts@plt>
  40093c:	d503201f 	nop
  400940:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400944:	d65f03c0 	ret

0000000000400948 <_ZN4Base6demo_2Ev>:
  400948:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  40094c:	910003fd 	mov	x29, sp
  400950:	f9000fa0 	str	x0, [x29, #24]
  400954:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  400958:	912b2000 	add	x0, x0, #0xac8
  40095c:	97ffff79 	bl	400740 <puts@plt>
  400960:	d503201f 	nop
  400964:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400968:	d65f03c0 	ret

000000000040096c <_ZN4Base6demo_3Ev>:
  40096c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400970:	910003fd 	mov	x29, sp
  400974:	f9000fa0 	str	x0, [x29, #24]
  400978:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  40097c:	912b6000 	add	x0, x0, #0xad8
  400980:	97ffff70 	bl	400740 <puts@plt>
  400984:	d503201f 	nop
  400988:	a8c27bfd 	ldp	x29, x30, [sp], #32
  40098c:	d65f03c0 	ret

0000000000400990 <_ZN7Derived4demoEv>:
  400990:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400994:	910003fd 	mov	x29, sp
  400998:	f9000fa0 	str	x0, [x29, #24]
  40099c:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  4009a0:	912bc000 	add	x0, x0, #0xaf0
  4009a4:	97ffff67 	bl	400740 <puts@plt>
  4009a8:	d503201f 	nop
  4009ac:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4009b0:	d65f03c0 	ret

00000000004009b4 <_ZN7Derived6demo_2Ev>:
  4009b4:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4009b8:	910003fd 	mov	x29, sp
  4009bc:	f9000fa0 	str	x0, [x29, #24]
  4009c0:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  4009c4:	912c0000 	add	x0, x0, #0xb00
  4009c8:	97ffff5e 	bl	400740 <puts@plt>
  4009cc:	d503201f 	nop
  4009d0:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4009d4:	d65f03c0 	ret

00000000004009d8 <_ZN7Derived6demo_3Ev>:
  4009d8:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4009dc:	910003fd 	mov	x29, sp
  4009e0:	f9000fa0 	str	x0, [x29, #24]
  4009e4:	90000000 	adrp	x0, 400000 <_init-0x6a0>
  4009e8:	912c4000 	add	x0, x0, #0xb10
  4009ec:	97ffff55 	bl	400740 <puts@plt>
  4009f0:	d503201f 	nop
  4009f4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4009f8:	d65f03c0 	ret
  4009fc:	00000000 	.inst	0x00000000 ; undefined

 #endif
